package com.mcf.xiaolinju.service.impl;

import com.mcf.xiaolinju.entity.Collection;
import com.mcf.xiaolinju.mapper.CollectionMapper;
import com.mcf.xiaolinju.service.ICollectionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author mcf
 * @since 2022-03-01
 */
@Service
public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collection> implements ICollectionService {
@Resource
CollectionMapper collectionMapper;
    public int selectcount(int id, int userid) {
        return collectionMapper.selectcount(id,userid);
    }



    public void updatecollection(int id, int userid) {
        if(collectionMapper.selectcount(id,userid)==1){
            collectionMapper.delmessage(id,userid);
        }
        else{
            Date date=new Date();
            LocalDateTime ldt=date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
            collectionMapper.insertmessage(id,userid,ldt);
        }
    }
}
